package com.zshy.base.core.context;

import lombok.experimental.UtilityClass;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 基础的上下文
 *
 * @author zhouhengzhe
 */
@UtilityClass
public class BaseContext {

    private final Map<Object, Object> GLOBAL = new ConcurrentHashMap<>();

    /**
     * 显式注入
     *
     * @param key
     * @param value
     */
    public void inject(Object key, Object value) {
        GLOBAL.put(key, value);
    }

    /**
     * 获取
     *
     * @param key
     * @param <T>
     * @return
     */
    public <T> T get(Object key) {
        return (T) GLOBAL.get(key);
    }

    /**
     * 是否包含
     *
     * @param key
     * @return
     */
    public boolean contains(Object key) {
        return GLOBAL.containsKey(key);
    }
}
